package com.googlecode.archimedes.filegen.model;

import java.util.Collection;

import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * <p>
 * Represents a relationship that inherits from another relationship. The end points of the
 * relationship must extend correctly from the parent class.
 * </p>
 * 
 * <p>Created: Mar 8, 2006</p>
 * 
 * @author Erik Gustavson
 * @version $Id: InheritedRelationship.java 2819 2006-08-22 18:35:24 +0000 (Tue, 22 Aug 2006) erik $
 */
public class InheritedRelationship extends Relationship {

    private Relationship parentRelationship = null;
    private String       parent             = null; //Used for parsing only - do not use

    /** 
     * @see com.tps.filegen.model.Relationship#getFromEntity()
     */
    @Override
    public AbstractType getFromEntity() {
        return getParentRelationship().getFromEntity();
    }

    /** 
     * @see com.tps.filegen.model.Relationship#getAssociation()
     */
    @Override
    public Association getAssociation() {
        return getParentRelationship().getAssociation();
    }

    /** 
     * @see com.tps.filegen.model.Relationship#getDir()
     */
    @Override
    public String getDir() {
        return getParentRelationship().getDir();
    }

    /** 
     * @see com.tps.filegen.model.Relationship#getDirection()
     */
    @Override
    public Direction getDirection() {
        return getParentRelationship().getDirection();
    }

    /** 
     * @see com.tps.filegen.model.Relationship#getInternalized()
     */
    @Override
    public boolean getInternalized() {
        return getParentRelationship().getInternalized();
    }

    /** 
     * @see com.tps.filegen.model.Relationship#getSubordinateAssets()
     */
    @Override
    public Collection<? extends Asset> getSubordinateAssets() {
        return getParentRelationship().getSubordinateAssets();
    }

    /** 
     * @see com.tps.filegen.model.Relationship#getType()
     */
    @Override
    public String getType() {
        return getParentRelationship().getType();
    }

    /** 
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 23).append(getName()).toHashCode();
    }

    /** 
     * @see com.tps.filegen.model.Relationship#isInternal()
     */
    @Override
    public boolean isInternal() {
        return getParentRelationship().isInternal();
    }

    /** 
     * @see com.tps.filegen.model.Relationship#setAssociation(com.tps.filegen.model.Relationship.Association)
     */
    @Override
    public void setAssociation(Association asociation) {
        //do nothing
    }

    /** 
     * @see com.tps.filegen.model.Relationship#setDir(java.lang.String)
     */
    @Override
    public void setDir(String dir) {
        //do nothing
    }

    /** 
     * @see com.tps.filegen.model.Relationship#setDirection(com.tps.filegen.model.Relationship.Direction)
     */
    @Override
    public void setDirection(Direction direction) {
        //do nothing
    }

    /** 
     * @see com.tps.filegen.model.Relationship#setInternal(boolean)
     */
    @Override
    public void setInternal(boolean internal) {
        //do nothing
    }

    /** 
     * @see com.tps.filegen.model.Relationship#setInternalized(boolean)
     */
    @Override
    public void setInternalized(boolean internalized) {
        //do nothing
    }

    /** 
     * @see com.tps.filegen.model.Relationship#setRestrictBeanPath(java.lang.String)
     */
    @Override
    public void setRestrictBeanPath(String restrictBeanPath) {
        //do nothing
    }

    /** 
     * @see com.tps.filegen.model.Relationship#setType(java.lang.String)
     */
    @Override
    public void setType(String type) {
        //do nothing
    }

    /** 
     * @see com.tps.filegen.model.Relationship#toString()
     */
    @Override
    public String toString() {
        return getParentRelationship() != null ? getParentRelationship().toString() : getParent();
    }

    /**
     * Returns the parent.
     *
     * @return Relationship value of parent
     */
    public Relationship getParentRelationship() {
        return parentRelationship;
    }

    /**
     * Sets the parent
     * @param parent The parent to set.
     */
    public void setParentRelationship(Relationship parent) {
        this.parentRelationship = parent;
    }

    /**
     * Returns the parent.
     *
     * @return String value of parent
     */
    public String getParent() {
        return parent;
    }

    /**
     * Sets the parent
     * @param parent The parent to set.
     */
    public void setParent(String parent) {
        this.parent = parent;
    }

}
